<?php

class Helper_Permission
{

    public function allow($action, $user = null)
    {

        if (null == $user)
        {
            $user = Agis::getViewer();
        }
        /**
         * get role id
         */
        $roleId = $user -> getRoleId();

        if ($roleId == 1 || $roleId == 2)
        {
            return 1;
        }

        $table = Agis::getTable('core@permission.acl');

        $select = $table -> select() -> where('actor=?', 'core@role:' . $roleId) -> where('action=?', $action);

        $row = $table -> fetchRow($select);

        if ($row)
        {
            return $row -> value;
        }

        return 0;
    }

}
